package com.whfc.ms.api.energy.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.energy.service.MsEnergyElectricityDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

//@RequiresPermissions("energy/device")
@RestController
@RequestMapping("/ms/api/energyElectricityData")
public class EnergyElectricityDataController extends BaseController {

    @Autowired
    private MsEnergyElectricityDataService msEnergyElectricityDataService;

    @GetMapping("/detailByTime")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestParam("deviceId") Integer deviceId,
                       @RequestParam("time") @DateTimeFormat(pattern = "yyyy-MM-dd") Date time) {

        logger.info("能耗电表根据时间获取最新详细数据：loginer:{},deviceId:{},time:{}", user.getUsername(), deviceId,time);
        return ResultUtil.success(msEnergyElectricityDataService.detailByTime(deviceId,time));
    }

    @GetMapping("/getEnergyElectricityWarnRule")
    public Result getEnergyElectricityWarnRule(@SessionAttribute(SessionAttr.MS_USER) SysUser user) {
        logger.info("能耗电表根据时间获取最新详细数据：loginer:{}", user.getUsername());
        return ResultUtil.success(msEnergyElectricityDataService.getEnergyElectricityWarnRule());
    }
}
